home *** CD-ROM | disk | FTP | other *** search
/ PC World 2006 September / PCWorld_2006-09_cd.bin / komercni software / zoner / zps8_cz.exe / {app} / HTMLPublish / compactPHP.zht / imgcmtnew.php < prev    next >
Encoding:
PHP Script  |  2006-03-22  |  3.9 KB  |  140 lines

  1. <?php
  2.  
  3. $id=$_GET["id"];
  4.  
  5. include_once("fn.php");
  6. $ip=FetchIP();
  7. $ipok=IPisOK($ip);
  8.  
  9. if ((strcmp($_POST["Person"],"")!=0 || strcmp($_POST["Comment"],"")!=0) && $ipok)
  10. {
  11.  
  12. $soubor="text/%num%.cmt";
  13. $soubor=str_replace("%num%",$id,$soubor);
  14.  
  15. $cmtmsk = "<COMMENT PERSON=\"%Person%\" MAIL=\"%Mail%\" WEB=\"%Web%\" TEXT=\"%Text%\" TIME=\"%time%\" IP=\"%ip%\" />\n";
  16.  
  17.  
  18. $outf="text/out%num%.txt";
  19. $outf=str_replace("%num%",$id,$outf);
  20.  
  21. $out = fopen($outf, "w");
  22. $time=time();
  23.  
  24. $person_in=$_POST["Person"];
  25. $mail_in=$_POST["Mail"];
  26. $web_in=$_POST["Web"];
  27. $comment_in=$_POST["Comment"];
  28.  
  29. ${STRIPTAGSDISABLER}
  30. {
  31. $person_in=strip_tags($person_in);
  32. $mail_in=strip_tags($mail_in);
  33. $web_in=strip_tags($web_in);
  34. $comment_in=strip_tags($comment_in);
  35. }
  36.  
  37. function startElement($parser, $name, $attrs) 
  38. {
  39.   if (strcmp($name,"COMMENTS")==0)
  40.   {
  41.      global $cmtmsk;
  42.      global $out;
  43.      global $time;
  44.      global $ip;
  45.      global $person_in;
  46.      global $mail_in;
  47.      global $web_in;
  48.      global $comment_in;
  49.      $cmtsmsk="<COMMENTS Count=\"%count%\">\n";
  50.      $cmtsmsk=str_replace("%count%",((int)$attrs['COUNT'])+1,$cmtsmsk);
  51.      fwrite($out, $cmtsmsk);
  52.      $res=str_replace("%Person%",makeXMLcompatible(charEncode($person_in)),$cmtmsk);
  53.      $res=str_replace("%Mail%",makeXMLcompatible(charEncode($mail_in)),$res);
  54.      $res=str_replace("%Web%",makeXMLcompatible(charEncode($web_in)),$res);
  55.      $res=str_replace("%Text%",makeXMLcompatible(charEncode($comment_in)),$res);
  56.      $res=str_replace("%time%",$time,$res);
  57.      $res=str_replace("%ip%",$ip,$res);
  58.      fwrite($out, $res);
  59.   }
  60.  
  61.   if (strcmp($name,"COMMENT")==0)
  62.   {
  63.      global $cmtmsk;
  64.      global $out;
  65.      $res=str_replace("%Person%",makeXMLcompatible($attrs['PERSON']),$cmtmsk);
  66.      $res=str_replace("%Mail%",makeXMLcompatible($attrs['MAIL']),$res);
  67.      $res=str_replace("%Web%",makeXMLcompatible($attrs['WEB']),$res);
  68.      $res=str_replace("%Text%",makeXMLcompatible($attrs['TEXT']),$res);
  69.      $res=str_replace("%time%",makeXMLcompatible($attrs['TIME']),$res);
  70.      $res=str_replace("%ip%",makeXMLcompatible($attrs['IP']),$res);
  71.      fwrite($out, $res);
  72.   }
  73. }
  74.  
  75. function endElement($parser, $name) 
  76. {
  77.   if (strcmp($name,"COMMENTS")==0)
  78.   {
  79.      global $out;
  80.      fwrite($out, "</COMMENTS>");
  81.   }
  82. }
  83.  
  84. if (file_exists($soubor)) 
  85. {
  86.   $xml_parser = xml_parser_create();
  87.   xml_set_element_handler($xml_parser, "startElement", "endElement");
  88.   if (!($fp = fopen($soubor, "r"))) {
  89.      die("could not open XML input");
  90.   }
  91.  
  92.  
  93.   fwrite($out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
  94.  
  95.   while ($xmldata = fread($fp, 4096)) {
  96.      if (!xml_parse($xml_parser, $xmldata, feof($fp))) {
  97.          die(sprintf("XML error: %s at line %d",
  98.                      xml_error_string(xml_get_error_code($xml_parser)),
  99.                      xml_get_current_line_number($xml_parser)));
  100.      }
  101.   }
  102.   xml_parser_free($xml_parser); 
  103.   fclose($fp);
  104. }
  105. else
  106. {
  107.   fwrite($out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
  108.   fwrite($out, "<COMMENTS Count=\"1\">");
  109.   $res=str_replace("%Person%",makeXMLcompatible(charEncode($person_in)),$cmtmsk);
  110.   $res=str_replace("%Mail%",makeXMLcompatible(charEncode($mail_in)),$res);
  111.   $res=str_replace("%Web%",makeXMLcompatible(charEncode($web_in)),$res);
  112.   $res=str_replace("%Text%",makeXMLcompatible(charEncode($comment_in)),$res);             
  113.   $res=str_replace("%time%",$time,$res);
  114.   $res=str_replace("%ip%",FetchIP(),$res);
  115.   fwrite($out, $res);
  116.   fwrite($out, "</COMMENTS>");
  117. }
  118.  
  119. fclose($out);
  120. copy($outf,$soubor);
  121. unlink($outf);
  122.  
  123. //  handle rss stuff
  124. //include_once("cmtrss.php");
  125. //UpdateCommentRSS(makeXMLcompatible(charEncode($_POST["Person"])),makeXMLcompatible(charEncode($_POST["Comment"])),$time,$id);
  126. //
  127. ${EMAILNOTIFICATION}
  128.  
  129. }
  130. if ($ipok)
  131. {
  132.   $refr="<meta http-equiv=\"refresh\" content=\"0; url=%id%.php\">";
  133.   $refr=str_replace("%id%",$id,$refr);
  134.   echo $refr;
  135. }
  136. else
  137.   echo "Zak├íz├íno";
  138.  
  139. ?>
  140.